# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Contributor: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Matthias Bauch <matthias.bauch@gmail.com>
# Contributor: Laszlo Papp <djszapi2 at gmail com>
# Contributor: Samuel Tardieu <sam@rfc1149.net>

_features=(amtjtagaccel armjtagew buspirate ftdi gw16012 jlink oocd_trace opendous osbdm
           parport presto_libftdi remote-bitbang rlink stlink ti-icdi ulink usbprog vsllink
           aice cmsis-dap dummy jtag_vpi openjtag_ftdi usb-blaster-2 usb_blaster_libftdi)

pkgname=openocd
pkgver=0.12.0
pkgrel=2
epoch=1
pkgdesc='Debugging, in-system programming and boundary-scan testing for embedded target devices'
arch=('loong64' 'x86_64')
url='http://openocd.org'
license=('GPL')
depends=('libftdi-compat' 'libusb-compat' 'hidapi' 'libudev.so')
source=("https://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.bz2")
sha512sums=('b32a8b9fe81ad23d8a544284f4bc626ca302e498dae95399a2f36756407dd1a63e8e9655ca1084e7cc13cf1b932d8f6a480f470a4c3ad502cd884ec7508738e9')

prepare() {
  cd $pkgname-$pkgver

  sed -i 's|GROUP="plugdev", ||g' contrib/60-openocd.rules
}

build() {
  cd $pkgname-$pkgver

  #libtoolize -vif
  #autoreconf -vif
  ./configure \
  	--prefix=/usr \
  	--disable-werror \
  	${_features[@]/#/--enable-}

  make
}

package() {
  cd $pkgname-$pkgver

  make DESTDIR="$pkgdir" install

  install -Dm 644 contrib/60-openocd.rules "$pkgdir"/usr/lib/udev/rules.d/60-openocd.rules
}
